package com.youlai.boot.system.controller;

import com.youlai.boot.system.service.SysEventCenterService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.boot.system.model.form.SysEventCenterForm;
import com.youlai.boot.system.model.query.SysEventCenterQuery;
import com.youlai.boot.system.model.vo.SysEventCenterVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 赛事中心前端控制层
 *
 * @author lwb
 * @since 2025-03-22 18:29
 */
@Tag(name = "赛事中心接口")
@RestController
@RequestMapping("/api/v1/sysEventCenters")
@RequiredArgsConstructor
public class SysEventCenterController  {

    private final SysEventCenterService sysEventCenterService;

    @Operation(summary = "赛事中心分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('system:sysEventCenter:query')")
    public PageResult<SysEventCenterVO> getSysEventCenterPage(SysEventCenterQuery queryParams ) {
        IPage<SysEventCenterVO> result = sysEventCenterService.getSysEventCenterPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增赛事中心")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('system:sysEventCenter:add')")
    public Result<Void> saveSysEventCenter(@RequestBody @Valid SysEventCenterForm formData ) {
        boolean result = sysEventCenterService.saveSysEventCenter(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取赛事中心表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('system:sysEventCenter:edit')")
    public Result<SysEventCenterForm> getSysEventCenterForm(
        @Parameter(description = "赛事中心ID") @PathVariable Long id
    ) {
        SysEventCenterForm formData = sysEventCenterService.getSysEventCenterFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改赛事中心")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('system:sysEventCenter:edit')")
    public Result<Void> updateSysEventCenter(
            @Parameter(description = "赛事中心ID") @PathVariable Long id,
            @RequestBody @Validated SysEventCenterForm formData
    ) {
        boolean result = sysEventCenterService.updateSysEventCenter(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除赛事中心")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('system:sysEventCenter:delete')")
    public Result<Void> deleteSysEventCenters(
        @Parameter(description = "赛事中心ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = sysEventCenterService.deleteSysEventCenters(ids);
        return Result.judge(result);
    }
}
